package com.apache.bid.controller.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultMsg;
import com.apache.bid.controller.BaseSupperAction;
import com.apache.bid.entity.BidOrg;
import com.apache.bid.manager.BidOrgManager;
import com.apache.bid.manager.UnityBaseManager;
import com.apache.cache.util.Validator;

@Controller
@RequestMapping("/admin/org")
public class BidOrgAction extends BaseSupperAction<BidOrg> {

	@Autowired
	private BidOrgManager bidOrgManager;

	@Override
	protected UnityBaseManager<BidOrg> getBaseManager() {
		return bidOrgManager;
	}

	public ResultMsg saveInfo(HttpServletRequest request, HttpServletResponse response, @ModelAttribute BidOrg item) {
		ResultMsg rmsg = new ResultMsg("T", "操作成功！");//用于封装结果信息
		response.setContentType("text/html");

		ParamsVo<BidOrg> vo = this.getParamsVo(request);//初始化参数vo对象，如果是登陆用户则获取用户信息及日志
		vo.setInfoId(item.getOrgId());
		BidOrg org = (BidOrg) bidOrgManager.getInfoById(vo);
		if (!Validator.isEmpty(org)) {
			rmsg = this.getResultMsg(request, "组织方[" + item.getOrgCname() + "]已创建，不能重复创建！");
			return rmsg;
		}
		//vo.setParams("loginUser", PBOSSOTools.getLoginUser(request));//存放当前登录用户
		vo.setObj(item);//新增
		String id = getBaseManager().saveInfo(vo);
		if (Validator.isNull(id)) {
			rmsg = new ResultMsg("F", "新增条目失败，请重试!");
		}
		return rmsg;
	}

	protected String getCommBoxValue(BidOrg item, String type) {
		if ("id".equals(type)) {
			return item.getOrgId();
		} else {
			return item.getOrgCname();
		}
	}

}
